package com.ykt.mall.ctrl;


import java.util.Date;

import com.jfinal.aop.Before;
import com.jfinal.ext.route.ControllerBind;
import com.ykt.mall.content.Content;
import com.ykt.mall.interceptor.LoginInterceptor;
import com.ykt.model.Customer;

@ControllerBind(controllerKey="/customer")
@Before(LoginInterceptor.class)//登陆拦截器
public class CustomerCtrl extends BaseWebController<Customer> {
	
	public void editPassword(){
	}
	public void edit(){
		setAttr("po", getLoginCustomer());
	}
	public void update(){
		Customer c =  getModel(Customer.class);
		c.set("update_time", new Date());
		c.update();
		setSessionAttr(Content.SESSION_LOGIN_USER, c);
		redirect("/customer");
	}
	public void updatePassword(){
		try{
			Customer loginCustomer = getLoginCustomer();
			if(!loginCustomer.get("password").equals(getPara("oldupwd"))){
				rendJson_(false,"原密码不正确");
				return ;
			}
			Customer customer = Customer.dao.findById(loginCustomer.get("id"));
			customer.set("password", getPara("upwd"));
			customer.set("update_time", new Date());
			customer.update();
			setLoginCustomer(customer);
			
			rendJson_(true,"密码修改成功");
		}catch(Exception e){
			e.printStackTrace();
			rendJson_(false,"密码修改失败");
		}
		
	}
}
